<template>
  <div class="my-tab-bar">
    <!-- current 控制高亮的类 -->
    <div
      class="tab-item"
      :class="{ current: value === index }"
      v-for="(item, index) in tabs"
      :key="index"
      @click="Highlight(index)"
    >
      <span class="iconfont" :class="item.icon"></span>
      <span>{{ item.title }}</span>
    </div>
    <!-- <div class="tab-item">
      <span class="iconfont icon-sousuo"></span>
      <span>商品搜索</span>
    </div>
    <div class="tab-item">
      <span class="iconfont icon-user"></span>
      <span>用户中心</span>
    </div> -->
  </div>
</template>

<script>
export default {
  props: {
    tabs: {
      type: Array,
      required: true,
      // 自定义校验规则
      validator: function (value) {
        if (value.length >= 2 && value.length <= 5) {
          return true;
        } else {
          console.error("tabs的长度必须是2到5位");
          return false;
        }
      },
    },
    value: {
      type: Number,
      default: 0,
    },
  },
  methods: {
    Highlight(index) {
      this.$emit("input", index);
    },
  },
};
</script>

<style lang="less" scoped>
.my-tab-bar {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  height: 50px;
  border-top: 1px solid #ccc;
  display: flex;
  justify-content: space-around;
  align-items: center;
  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    .iconfont {
      font-size: 18px;
    }
  }
  .current {
    color: #1d7bff;
  }
}
</style>